home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / docs / gdb / gdb.i1 next >
Encoding:
GNU Info File  |  1994-07-26  |  48.6 KB  |  1,276 lines

  1. This is Info file ./gdb.info, produced by Makeinfo-1.52 from the input
  2. file gdb.texinfo.
  3.  
  4. START-INFO-DIR-ENTRY
  5. * Gdb::                         The GNU debugger.
  6. END-INFO-DIR-ENTRY
  7.    This file documents the GNU debugger GDB.
  8.  
  9.    This is Edition 4.12, January 1994, of `Debugging with GDB: the GNU
  10. Source-Level Debugger' for GDB Version 4.12.
  11.  
  12.    Copyright (C) 1988, '89, '90, '91, '92, '93 Free Software
  13. Foundation, Inc.
  14.  
  15.    Permission is granted to make and distribute verbatim copies of this
  16. manual provided the copyright notice and this permission notice are
  17. preserved on all copies.
  18.  
  19.    Permission is granted to copy and distribute modified versions of
  20. this manual under the conditions for verbatim copying, provided also
  21. that the entire resulting derived work is distributed under the terms
  22. of a permission notice identical to this one.
  23.  
  24.    Permission is granted to copy and distribute translations of this
  25. manual into another language, under the above conditions for modified
  26. versions.
  27.  
  28. 
  29. File: gdb.info,  Node: Top,  Next: Summary,  Prev: (DIR),  Up: (DIR)
  30.  
  31. Debugging with GDB
  32. ******************
  33.  
  34.    This file describes GDB, the GNU symbolic debugger.
  35.  
  36.    This is Edition 4.12, January 1994, for GDB Version 4.12.
  37.  
  38. * Menu:
  39.  
  40. * Summary::                     Summary of GDB
  41.  
  42. * New Features::                New features since GDB version 3.5
  43.  
  44. * Sample Session::              A sample GDB session
  45.  
  46. * Invocation::                  Getting in and out of GDB
  47. * Commands::                    GDB commands
  48. * Running::                     Running programs under GDB
  49. * Stopping::                    Stopping and continuing
  50. * Stack::                       Examining the stack
  51. * Source::                      Examining source files
  52. * Data::                        Examining data
  53.  
  54. * Languages::                   Using GDB with different languages
  55.  
  56.  
  57. * Symbols::                     Examining the symbol table
  58. * Altering::                    Altering execution
  59. * GDB Files::                   GDB files
  60. * Targets::                     Specifying a debugging target
  61. * Controlling GDB::             Controlling GDB
  62. * Sequences::                   Canned sequences of commands
  63.  
  64. * Emacs::                       Using GDB under GNU Emacs
  65.  
  66. * GDB Bugs::                    Reporting bugs in GDB
  67. * Command Line Editing::        Facilities of the readline library
  68. * Using History Interactively::
  69.  
  70. * Renamed Commands::
  71.  
  72. * Formatting Documentation::    How to format and print GDB documentation
  73. * Installing GDB::              Installing GDB
  74.  
  75. * Index::                       Index
  76.  
  77. 
  78. File: gdb.info,  Node: Summary,  Next: New Features,  Prev: Top,  Up: Top
  79.  
  80. Summary of GDB
  81. **************
  82.  
  83.    The purpose of a debugger such as GDB is to allow you to see what is
  84. going on "inside" another program while it executes--or what another
  85. program was doing at the moment it crashed.
  86.  
  87.    GDB can do four main kinds of things (plus other things in support of
  88. these) to help you catch bugs in the act:
  89.  
  90.    * Start your program, specifying anything that might affect its
  91.      behavior.
  92.  
  93.    * Make your program stop on specified conditions.
  94.  
  95.    * Examine what has happened, when your program has stopped.
  96.  
  97.    * Change things in your program, so you can experiment with
  98.      correcting the effects of one bug and go on to learn about another.
  99.  
  100.    You can use GDB to debug programs written in C or C++.  For more
  101. information, see *Note C and C++: C.
  102.  
  103.    Support for Modula-2 and Chill is partial.  For information on
  104. Modula-2, see *Note Modula-2: Modula-2.  There is no further
  105. documentation on Chill yet.
  106.  
  107.    Debugging Pascal programs which use sets, subranges, file variables,
  108. or nested functions does not currently work.  GDB does not support
  109. entering expressions, printing values, or similar features using Pascal
  110. syntax.  GDB can be used to debug programs written in Fortran, although
  111. it does not yet support entering expressions, printing values, or
  112. similar features using Fortran syntax.  It may be necessary to refer to
  113. some variables with a trailing underscore.
  114.  
  115. * Menu:
  116.  
  117. * Free Software::               Freely redistributable software
  118. * Contributors::                Contributors to GDB
  119.  
  120. 
  121. File: gdb.info,  Node: Free Software,  Next: Contributors,  Up: Summary
  122.  
  123. Free software
  124. =============
  125.  
  126.    GDB is "free software", protected by the GNU General Public License
  127. (GPL).  The GPL gives you the freedom to copy or adapt a licensed
  128. program--but every person getting a copy also gets with it the freedom
  129. to modify that copy (which means that they must get access to the
  130. source code), and the freedom to distribute further copies.  Typical
  131. software companies use copyrights to limit your freedoms; the Free
  132. Software Foundation uses the GPL to preserve these freedoms.
  133.  
  134.    Fundamentally, the General Public License is a license which says
  135. that you have these freedoms and that you cannot take these freedoms
  136. away from anyone else.
  137.  
  138. 
  139. File: gdb.info,  Node: Contributors,  Prev: Free Software,  Up: Summary
  140.  
  141. Contributors to GDB
  142. ===================
  143.  
  144.    Richard Stallman was the original author of GDB, and of many other
  145. GNU programs.  Many others have contributed to its development.  This
  146. section attempts to credit major contributors.  One of the virtues of
  147. free software is that everyone is free to contribute to it; with
  148. regret, we cannot actually acknowledge everyone here.  The file
  149. `ChangeLog' in the GDB distribution approximates a blow-by-blow account.
  150.  
  151.    Changes much prior to version 2.0 are lost in the mists of time.
  152.  
  153.      *Plea:* Additions to this section are particularly welcome.  If you
  154.      or your friends (or enemies, to be evenhanded) have been unfairly
  155.      omitted from this list, we would like to add your names!
  156.  
  157.    So that they may not regard their long labor as thankless, we
  158. particularly thank those who shepherded GDB through major releases: Fred
  159. Fish (releases 4.12, 4.11, 4.10, 4.9), Stu Grossman and John Gilmore
  160. (releases 4.8, 4.7, 4.6, 4.5, 4.4), John Gilmore (releases 4.3, 4.2,
  161. 4.1, 4.0, and 3.9); Jim Kingdon (releases 3.5, 3.4, 3.3); and Randy
  162. Smith (releases 3.2, 3.1, 3.0).  As major maintainer of GDB for some
  163. period, each contributed significantly to the structure, stability, and
  164. capabilities of the entire debugger.
  165.  
  166.    Richard Stallman, assisted at various times by Peter TerMaat, Chris
  167. Hanson, and Richard Mlynarik, handled releases through 2.8.
  168.  
  169.    Michael Tiemann is the author of most of the GNU C++ support in GDB,
  170. with significant additional contributions from Per Bothner.  James
  171. Clark wrote the GNU C++ demangler.  Early work on C++ was by Peter
  172. TerMaat (who also did much general update work leading to release 3.0).
  173.  
  174.    GDB 4 uses the BFD subroutine library to examine multiple
  175. object-file formats; BFD was a joint project of David V.
  176. Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
  177.  
  178.    David Johnson wrote the original COFF support; Pace Willison did the
  179. original support for encapsulated COFF.
  180.  
  181.    Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
  182. Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
  183. support.  Jean-Daniel Fekete contributed Sun 386i support.  Chris
  184. Hanson improved the HP9000 support.  Noboyuki Hikichi and Tomoyuki
  185. Hasei contributed Sony/News OS 3 support.  David Johnson contributed
  186. Encore Umax support.  Jyrki Kuoppala contributed Altos 3068 support.
  187. Keith Packard contributed NS32K support.  Doug Rabson contributed Acorn
  188. Risc Machine support.  Chris Smith contributed Convex support (and
  189. Fortran debugging).  Jonathan Stone contributed Pyramid support.
  190. Michael Tiemann contributed SPARC support.  Tim Tucker contributed
  191. support for the Gould NP1 and Gould Powernode.  Pace Willison
  192. contributed Intel 386 support.  Jay Vosburgh contributed Symmetry
  193. support.
  194.  
  195.    Rich Schaefer and Peter Schauer helped with support of SunOS shared
  196. libraries.
  197.  
  198.    Jay Fenlason and Roland McGrath ensured that GDB and GAS agree about
  199. several machine instruction sets.
  200.  
  201.    Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped
  202. develop remote debugging.  Intel Corporation and Wind River Systems
  203. contributed remote debugging modules for their products.
  204.  
  205.    Brian Fox is the author of the readline libraries providing
  206. command-line editing and command history.
  207.  
  208.    Andrew Beers of SUNY Buffalo wrote the language-switching code, the
  209. Modula-2 support, and contributed the Languages chapter of this manual.
  210.  
  211.    Fred Fish wrote most of the support for Unix System Vr4.  He also
  212. enhanced the command-completion support to cover C++ overloaded symbols.
  213.  
  214.    Hitachi America, Ltd. sponsored the support for Hitachi
  215. microprocessors.
  216.  
  217. 
  218. File: gdb.info,  Node: New Features,  Next: Sample Session,  Prev: Summary,  Up: Top
  219.  
  220. New Features since GDB Version 3.5
  221. **********************************
  222.  
  223. *Targets*
  224.      Using the new command `target', you can select at runtime whether
  225.      you are debugging local files, local processes, standalone systems
  226.      over a serial port, or realtime systems over a TCP/IP connection.
  227.      The command `load' can download programs into a remote system.
  228.      Serial stubs are available for Motorola 680x0, Intel 80386, and
  229.      Sparc remote systems; GDB also supports debugging realtime
  230.      processes running under VxWorks, using SunRPC Remote Procedure
  231.      Calls over TCP/IP to talk to a debugger stub on the target system.
  232.      Internally, GDB now uses a function vector to mediate access to
  233.      different targets; if you need to add your own support for a
  234.      remote protocol, this makes it much easier.
  235.  
  236. *Watchpoints*
  237.      GDB now sports watchpoints as well as breakpoints.  You can use a
  238.      watchpoint to stop execution whenever the value of an expression
  239.      changes, without having to predict a particular place in your
  240.      program where this may happen.
  241.  
  242. *Wide Output*
  243.      Commands that issue wide output now insert newlines at places
  244.      designed to make the output more readable.
  245.  
  246. *Object Code Formats*
  247.      GDB uses a new library called the Binary File Descriptor (BFD)
  248.      Library to permit it to switch dynamically, without
  249.      reconfiguration or recompilation, between different object-file
  250.      formats.  Formats currently supported are COFF, ELF, a.out, Intel
  251.      960 b.out, MIPS ECOFF, HPPA SOM (with stabs debugging), and
  252.      S-records; files may be read as .o files, archive libraries, or
  253.      core dumps.  BFD is available as a subroutine library so that
  254.      other programs may take advantage of it, and the other GNU binary
  255.      utilities are being converted to use it.
  256.  
  257. *Configuration and Ports*
  258.      Compile-time configuration (to select a particular architecture and
  259.      operating system) is much easier.  The script `configure' now
  260.      allows you to configure GDB as either a native debugger or a
  261.      cross-debugger. *Note Installing GDB::, for details on how to
  262.      configure.
  263.  
  264. *Interaction*
  265.      The user interface to the GDB control variables is simpler, and is
  266.      consolidated in two commands, `set' and `show'.  Output lines are
  267.      now broken at readable places, rather than overflowing onto the
  268.      next line.  You can suppress output of machine-level addresses,
  269.      displaying only source language information.
  270.  
  271. *C++*
  272.      GDB now supports C++ multiple inheritance (if used with a GCC
  273.      version 2 compiler), and also has limited support for C++ exception
  274.      handling, with the commands `catch' and `info catch': GDB can
  275.      break when an exception is raised, before the stack is peeled back
  276.      to the exception handler's context.
  277.  
  278. *Modula-2*
  279.      GDB now has preliminary support for the GNU Modula-2 compiler,
  280.      currently under development at the State University of New York at
  281.      Buffalo.  Coordinated development of both GDB and the GNU Modula-2
  282.      compiler will continue.  Other Modula-2 compilers are currently
  283.      not supported, and attempting to debug programs compiled with them
  284.      will likely result in an error as the symbol table of the
  285.      executable is read in.
  286.  
  287. *Command Rationalization*
  288.      Many GDB commands have been renamed to make them easier to remember
  289.      and use.  In particular, the subcommands of `info' and
  290.      `show'/`set' are grouped to make the former refer to the state of
  291.      your program, and the latter refer to the state of GDB itself.
  292.      *Note Renamed Commands::, for details on what commands were
  293.      renamed.
  294.  
  295. *Shared Libraries*
  296.      GDB 4 can debug programs and core files that use SunOS, SVR4, or
  297.      IBM RS/6000 shared libraries.
  298.  
  299. *Threads*
  300.      On some systems, GDB 4 has facilities to debug multi-thread
  301.      programs.
  302.  
  303. *Reference Card*
  304.      GDB 4 has a reference card.  *Note Formatting the Documentation:
  305.      Formatting Documentation, for instructions about how to print it.
  306.  
  307. 
  308. File: gdb.info,  Node: Sample Session,  Next: Invocation,  Prev: New Features,  Up: Top
  309.  
  310. A Sample GDB Session
  311. ********************
  312.  
  313.    You can use this manual at your leisure to read all about GDB.
  314. However, a handful of commands are enough to get started using the
  315. debugger.  This chapter illustrates those commands.
  316.  
  317.    One of the preliminary versions of GNU `m4' (a generic macro
  318. processor) exhibits the following bug: sometimes, when we change its
  319. quote strings from the default, the commands used to capture one macro
  320. definition within another stop working.  In the following short `m4'
  321. session, we define a macro `foo' which expands to `0000'; we then use
  322. the `m4' built-in `defn' to define `bar' as the same thing.  However,
  323. when we change the open quote string to `<QUOTE>' and the close quote
  324. string to `<UNQUOTE>', the same procedure fails to define a new synonym
  325. `baz':
  326.  
  327.      $ cd gnu/m4
  328.      $ ./m4
  329.      define(foo,0000)
  330.      
  331.      foo
  332.      0000
  333.      define(bar,defn(`foo'))
  334.      
  335.      bar
  336.      0000
  337.      changequote(<QUOTE>,<UNQUOTE>)
  338.      
  339.      define(baz,defn(<QUOTE>foo<UNQUOTE>))
  340.      baz
  341.      C-d
  342.      m4: End of input: 0: fatal error: EOF in string
  343.  
  344. Let us use GDB to try to see what is going on.
  345.  
  346.      $ gdb m4
  347.      GDB is free software and you are welcome to distribute copies
  348.       of it under certain conditions; type "show copying" to see
  349.       the conditions.
  350.      There is absolutely no warranty for GDB; type "show warranty"
  351.       for details.
  352.      GDB 4.12, Copyright 1993 Free Software Foundation, Inc...
  353.      (gdb)
  354.  
  355. GDB reads only enough symbol data to know where to find the rest when
  356. needed; as a result, the first prompt comes up very quickly.  We now
  357. tell GDB to use a narrower display width than usual, so that examples
  358. fit in this manual.
  359.  
  360.      (gdb) set width 70
  361.  
  362. We need to see how the `m4' built-in `changequote' works.  Having
  363. looked at the source, we know the relevant subroutine is
  364. `m4_changequote', so we set a breakpoint there with the GDB `break'
  365. command.
  366.  
  367.      (gdb) break m4_changequote
  368.      Breakpoint 1 at 0x62f4: file builtin.c, line 879.
  369.  
  370. Using the `run' command, we start `m4' running under GDB control; as
  371. long as control does not reach the `m4_changequote' subroutine, the
  372. program runs as usual:
  373.  
  374.      (gdb) run
  375.      Starting program: /work/Editorial/gdb/gnu/m4/m4
  376.      define(foo,0000)
  377.      
  378.      foo
  379.      0000
  380.  
  381. To trigger the breakpoint, we call `changequote'.  GDB suspends
  382. execution of `m4', displaying information about the context where it
  383. stops.
  384.  
  385.      changequote(<QUOTE>,<UNQUOTE>)
  386.      
  387.      Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
  388.          at builtin.c:879
  389.      879         if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
  390.  
  391. Now we use the command `n' (`next') to advance execution to the next
  392. line of the current function.
  393.  
  394.      (gdb) n
  395.      882         set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
  396.       : nil,
  397.  
  398. `set_quotes' looks like a promising subroutine.  We can go into it by
  399. using the command `s' (`step') instead of `next'.  `step' goes to the
  400. next line to be executed in *any* subroutine, so it steps into
  401. `set_quotes'.
  402.  
  403.      (gdb) s
  404.      set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
  405.          at input.c:530
  406.      530         if (lquote != def_lquote)
  407.  
  408. The display that shows the subroutine where `m4' is now suspended (and
  409. its arguments) is called a stack frame display.  It shows a summary of
  410. the stack.  We can use the `backtrace' command (which can also be
  411. spelled `bt'), to see where we are in the stack as a whole: the
  412. `backtrace' command displays a stack frame for each active subroutine.
  413.  
  414.      (gdb) bt
  415.      #0  set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
  416.          at input.c:530
  417.      #1  0x6344 in m4_changequote (argc=3, argv=0x33c70)
  418.          at builtin.c:882
  419.      #2  0x8174 in expand_macro (sym=0x33320) at macro.c:242
  420.      #3  0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
  421.          at macro.c:71
  422.      #4  0x79dc in expand_input () at macro.c:40
  423.      #5  0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
  424.  
  425. We step through a few more lines to see what happens.  The first two
  426. times, we can use `s'; the next two times we use `n' to avoid falling
  427. into the `xstrdup' subroutine.
  428.  
  429.      (gdb) s
  430.      0x3b5c  532         if (rquote != def_rquote)
  431.      (gdb) s
  432.      0x3b80  535         lquote = (lq == nil || *lq == '\0') ?  \
  433.      def_lquote : xstrdup(lq);
  434.      (gdb) n
  435.      536         rquote = (rq == nil || *rq == '\0') ? def_rquote\
  436.       : xstrdup(rq);
  437.      (gdb) n
  438.      538         len_lquote = strlen(rquote);
  439.  
  440. The last line displayed looks a little odd; we can examine the variables
  441. `lquote' and `rquote' to see if they are in fact the new left and right
  442. quotes we specified.  We use the command `p' (`print') to see their
  443. values.
  444.  
  445.      (gdb) p lquote
  446.      $1 = 0x35d40 "<QUOTE>"
  447.      (gdb) p rquote
  448.      $2 = 0x35d50 "<UNQUOTE>"
  449.  
  450. `lquote' and `rquote' are indeed the new left and right quotes.  To
  451. look at some context, we can display ten lines of source surrounding
  452. the current line with the `l' (`list') command.
  453.  
  454.      (gdb) l
  455.      533             xfree(rquote);
  456.      534
  457.      535         lquote = (lq == nil || *lq == '\0') ? def_lquote\
  458.       : xstrdup (lq);
  459.      536         rquote = (rq == nil || *rq == '\0') ? def_rquote\
  460.       : xstrdup (rq);
  461.      537
  462.      538         len_lquote = strlen(rquote);
  463.      539         len_rquote = strlen(lquote);
  464.      540     }
  465.      541
  466.      542     void
  467.  
  468. Let us step past the two lines that set `len_lquote' and `len_rquote',
  469. and then examine the values of those variables.
  470.  
  471.      (gdb) n
  472.      539         len_rquote = strlen(lquote);
  473.      (gdb) n
  474.      540     }
  475.      (gdb) p len_lquote
  476.      $3 = 9
  477.      (gdb) p len_rquote
  478.      $4 = 7
  479.  
  480. That certainly looks wrong, assuming `len_lquote' and `len_rquote' are
  481. meant to be the lengths of `lquote' and `rquote' respectively.  We can
  482. set them to better values using the `p' command, since it can print the
  483. value of any expression--and that expression can include subroutine
  484. calls and assignments.
  485.  
  486.      (gdb) p len_lquote=strlen(lquote)
  487.      $5 = 7
  488.      (gdb) p len_rquote=strlen(rquote)
  489.      $6 = 9
  490.  
  491. Is that enough to fix the problem of using the new quotes with the `m4'
  492. built-in `defn'?  We can allow `m4' to continue executing with the `c'
  493. (`continue') command, and then try the example that caused trouble
  494. initially:
  495.  
  496.      (gdb) c
  497.      Continuing.
  498.      
  499.      define(baz,defn(<QUOTE>foo<UNQUOTE>))
  500.      
  501.      baz
  502.      0000
  503.  
  504. Success!  The new quotes now work just as well as the default ones.  The
  505. problem seems to have been just the two typos defining the wrong
  506. lengths.  We allow `m4' exit by giving it an EOF as input:
  507.  
  508.      C-d
  509.      Program exited normally.
  510.  
  511. The message `Program exited normally.' is from GDB; it indicates `m4'
  512. has finished executing.  We can end our GDB session with the GDB `quit'
  513. command.
  514.  
  515.      (gdb) quit
  516.  
  517. 
  518. File: gdb.info,  Node: Invocation,  Next: Commands,  Prev: Sample Session,  Up: Top
  519.  
  520. Getting In and Out of GDB
  521. *************************
  522.  
  523.    This chapter discusses how to start GDB, and how to get out of it.
  524. (The essentials: type `gdb' to start GDB, and type `quit' or `C-d' to
  525. exit.)
  526.  
  527. * Menu:
  528.  
  529. * Invoking GDB::                How to start GDB
  530. * Quitting GDB::                 How to quit GDB
  531. * Shell Commands::              How to use shell commands inside GDB
  532.  
  533. 
  534. File: gdb.info,  Node: Invoking GDB,  Next: Quitting GDB,  Up: Invocation
  535.  
  536. Invoking GDB
  537. ============
  538.  
  539.    Invoke GDB by running the program `gdb'.  Once started, GDB reads
  540. commands from the terminal until you tell it to exit.
  541.  
  542.    You can also run `gdb' with a variety of arguments and options, to
  543. specify more of your debugging environment at the outset.
  544.  
  545.    The command-line options described here are designed to cover a
  546. variety of situations; in some environments, some of these options may
  547. effectively be unavailable.
  548.  
  549.    The most usual way to start GDB is with one argument, specifying an
  550. executable program:
  551.  
  552.      gdb PROGRAM
  553.  
  554. You can also start with both an executable program and a core file
  555. specified:
  556.  
  557.      gdb PROGRAM CORE
  558.  
  559.    You can, instead, specify a process ID as a second argument, if you
  560. want to debug a running process:
  561.  
  562.      gdb PROGRAM 1234
  563.  
  564. would attach GDB to process `1234' (unless you also have a file named
  565. `1234'; GDB does check for a core file first).
  566.  
  567.    Taking advantage of the second command-line argument requires a
  568. fairly complete operating system; when you use GDB as a remote debugger
  569. attached to a bare board, there may not be any notion of "process", and
  570. there is often no way to get a core dump.
  571.  
  572. You can further control how GDB starts up by using command-line
  573. options.  GDB itself can remind you of the options available.
  574.  
  575. Type
  576.  
  577.      gdb -help
  578.  
  579. to display all available options and briefly describe their use (`gdb
  580. -h' is a shorter equivalent).
  581.  
  582.    All options and command line arguments you give are processed in
  583. sequential order.  The order makes a difference when the `-x' option is
  584. used.
  585.  
  586. * Menu:
  587.  
  588.  
  589.  
  590. * File Options::                Choosing files
  591. * Mode Options::                Choosing modes
  592.  
  593. 
  594. File: gdb.info,  Node: File Options,  Next: Mode Options,  Up: Invoking GDB
  595.  
  596. Choosing files
  597. --------------
  598.  
  599.    When GDB starts, it reads any arguments other than options as
  600. specifying an executable file and core file (or process ID).  This is
  601. the same as if the arguments were specified by the `-se' and `-c'
  602. options respectively.  (GDB reads the first argument that does not have
  603. an associated option flag as equivalent to the `-se' option followed by
  604. that argument; and the second argument that does not have an associated
  605. option flag, if any, as equivalent to the `-c' option followed by that
  606. argument.)
  607.  
  608.    Many options have both long and short forms; both are shown in the
  609. following list.  GDB also recognizes the long forms if you truncate
  610. them, so long as enough of the option is present to be unambiguous.
  611. (If you prefer, you can flag option arguments with `--' rather than
  612. `-', though we illustrate the more usual convention.)
  613.  
  614. `-symbols FILE'
  615. `-s FILE'
  616.      Read symbol table from file FILE.
  617.  
  618. `-exec FILE'
  619. `-e FILE'
  620.      Use file FILE as the executable file to execute when appropriate,
  621.      and for examining pure data in conjunction with a core dump.
  622.  
  623. `-se FILE'
  624.      Read symbol table from file FILE and use it as the executable file.
  625.  
  626. `-core FILE'
  627. `-c FILE'
  628.      Use file FILE as a core dump to examine.
  629.  
  630. `-c NUMBER'
  631.      Connect to process ID NUMBER, as with the `attach' command (unless
  632.      there is a file in core-dump format named NUMBER, in which case
  633.      `-c' specifies that file as a core dump to read).
  634.  
  635. `-command FILE'
  636. `-x FILE'
  637.      Execute GDB commands from file FILE.  *Note Command files: Command
  638.      Files.
  639.  
  640. `-directory DIRECTORY'
  641. `-d DIRECTORY'
  642.      Add DIRECTORY to the path to search for source files.
  643.  
  644. `-m'
  645. `-mapped'
  646.      *Warning: this option depends on operating system facilities that
  647.      are not supported on all systems.*
  648.      If memory-mapped files are available on your system through the
  649.      `mmap' system call, you can use this option to have GDB write the
  650.      symbols from your program into a reusable file in the current
  651.      directory.  If the program you are debugging is called
  652.      `/tmp/fred', the mapped symbol file is `./fred.syms'.  Future GDB
  653.      debugging sessions notice the presence of this file, and can
  654.      quickly map in symbol information from it, rather than reading the
  655.      symbol table from the executable program.
  656.  
  657.      The `.syms' file is specific to the host machine where GDB is run.
  658.      It holds an exact image of the internal GDB symbol table.  It
  659.      cannot be shared across multiple host platforms.
  660.  
  661. `-r'
  662. `-readnow'
  663.      Read each symbol file's entire symbol table immediately, rather
  664.      than the default, which is to read it incrementally as it is
  665.      needed.  This makes startup slower, but makes future operations
  666.      faster.
  667.  
  668.    The `-mapped' and `-readnow' options are typically combined in order
  669. to build a `.syms' file that contains complete symbol information.
  670. (*Note Commands to specify files: Files, for information on `.syms'
  671. files.)  A simple GDB invocation to do nothing but build a `.syms' file
  672. for future use is:
  673.  
  674.          gdb -batch -nx -mapped -readnow programname
  675.  
  676. 
  677. File: gdb.info,  Node: Mode Options,  Prev: File Options,  Up: Invoking GDB
  678.  
  679. Choosing modes
  680. --------------
  681.  
  682.    You can run GDB in various alternative modes--for example, in batch
  683. mode or quiet mode.
  684.  
  685. `-nx'
  686. `-n'
  687.      Do not execute commands from any initialization files (normally
  688.      called `.gdbinit').  Normally, the commands in these files are
  689.      executed after all the command options and arguments have been
  690.      processed.  *Note Command files: Command Files.
  691.  
  692. `-quiet'
  693. `-q'
  694.      "Quiet".  Do not print the introductory and copyright messages.
  695.      These messages are also suppressed in batch mode.
  696.  
  697. `-batch'
  698.      Run in batch mode.  Exit with status `0' after processing all the
  699.      command files specified with `-x' (and all commands from
  700.      initialization files, if not inhibited with `-n').  Exit with
  701.      nonzero status if an error occurs in executing the GDB commands in
  702.      the command files.
  703.  
  704.      Batch mode may be useful for running GDB as a filter, for example
  705.      to download and run a program on another computer; in order to
  706.      make this more useful, the message
  707.  
  708.           Program exited normally.
  709.  
  710.      (which is ordinarily issued whenever a program running under GDB
  711.      control terminates) is not issued when running in batch mode.
  712.  
  713. `-cd DIRECTORY'
  714.      Run GDB using DIRECTORY as its working directory, instead of the
  715.      current directory.
  716.  
  717. `-fullname'
  718. `-f'
  719.      Emacs sets this option when it runs GDB as a subprocess.  It tells
  720.      GDB to output the full file name and line number in a standard,
  721.      recognizable fashion each time a stack frame is displayed (which
  722.      includes each time your program stops).  This recognizable format
  723.      looks like two `\032' characters, followed by the file name, line
  724.      number and character position separated by colons, and a newline.
  725.      The Emacs-to-GDB interface program uses the two `\032' characters
  726.      as a signal to display the source code for the frame.
  727.  
  728. `-b BPS'
  729.      Set the line speed (baud rate or bits per second) of any serial
  730.      interface used by GDB for remote debugging.
  731.  
  732. `-tty DEVICE'
  733.      Run using DEVICE for your program's standard input and output.
  734.  
  735. 
  736. File: gdb.info,  Node: Quitting GDB,  Next: Shell Commands,  Prev: Invoking GDB,  Up: Invocation
  737.  
  738. Quitting GDB
  739. ============
  740.  
  741. `quit'
  742.      To exit GDB, use the `quit' command (abbreviated `q'), or type an
  743.      end-of-file character (usually `C-d').
  744.  
  745.    An interrupt (often `C-c') does not exit from GDB, but rather
  746. terminates the action of any GDB command that is in progress and
  747. returns to GDB command level.  It is safe to type the interrupt
  748. character at any time because GDB does not allow it to take effect
  749. until a time when it is safe.
  750.  
  751.    If you have been using GDB to control an attached process or device,
  752. you can release it with the `detach' command (*note Debugging an
  753. already-running process: Attach.).
  754.  
  755. 
  756. File: gdb.info,  Node: Shell Commands,  Prev: Quitting GDB,  Up: Invocation
  757.  
  758. Shell commands
  759. ==============
  760.  
  761.    If you need to execute occasional shell commands during your
  762. debugging session, there is no need to leave or suspend GDB; you can
  763. just use the `shell' command.
  764.  
  765. `shell COMMAND STRING'
  766.      Invoke a the standard shell to execute COMMAND STRING.  If it
  767.      exists, the environment variable `SHELL' determines which shell to
  768.      run.  Otherwise GDB uses `/bin/sh'.
  769.  
  770.    The utility `make' is often needed in development environments.  You
  771. do not have to use the `shell' command for this purpose in GDB:
  772.  
  773. `make MAKE-ARGS'
  774.      Execute the `make' program with the specified arguments.  This is
  775.      equivalent to `shell make MAKE-ARGS'.
  776.  
  777. 
  778. File: gdb.info,  Node: Commands,  Next: Running,  Prev: Invocation,  Up: Top
  779.  
  780. GDB Commands
  781. ************
  782.  
  783.    You can abbreviate a GDB command to the first few letters of the
  784. command name, if that abbreviation is unambiguous; and you can repeat
  785. certain GDB commands by typing just RET.  You can also use the TAB key
  786. to get GDB to fill out the rest of a word in a command (or to show you
  787. the alternatives available, if there is more than one possibility).
  788.  
  789. * Menu:
  790.  
  791. * Command Syntax::              How to give commands to GDB
  792. * Completion::                  Command completion
  793. * Help::                        How to ask GDB for help
  794.  
  795. 
  796. File: gdb.info,  Node: Command Syntax,  Next: Completion,  Up: Commands
  797.  
  798. Command syntax
  799. ==============
  800.  
  801.    A GDB command is a single line of input.  There is no limit on how
  802. long it can be.  It starts with a command name, which is followed by
  803. arguments whose meaning depends on the command name.  For example, the
  804. command `step' accepts an argument which is the number of times to
  805. step, as in `step 5'.  You can also use the `step' command with no
  806. arguments.  Some command names do not allow any arguments.
  807.  
  808.    GDB command names may always be truncated if that abbreviation is
  809. unambiguous.  Other possible command abbreviations are listed in the
  810. documentation for individual commands.  In some cases, even ambiguous
  811. abbreviations are allowed; for example, `s' is specially defined as
  812. equivalent to `step' even though there are other commands whose names
  813. start with `s'.  You can test abbreviations by using them as arguments
  814. to the `help' command.
  815.  
  816.    A blank line as input to GDB (typing just RET) means to repeat the
  817. previous command. Certain commands (for example, `run') will not repeat
  818. this way; these are commands whose unintentional repetition might cause
  819. trouble and which you are unlikely to want to repeat.
  820.  
  821.    The `list' and `x' commands, when you repeat them with RET,
  822. construct new arguments rather than repeating exactly as typed.  This
  823. permits easy scanning of source or memory.
  824.  
  825.    GDB can also use RET in another way: to partition lengthy output, in
  826. a way similar to the common utility `more' (*note Screen size: Screen
  827. Size.).  Since it is easy to press one RET too many in this situation,
  828. GDB disables command repetition after any command that generates this
  829. sort of display.
  830.  
  831.    Any text from a `#' to the end of the line is a comment; it does
  832. nothing.  This is useful mainly in command files (*note Command files:
  833. Command Files.).
  834.  
  835. 
  836. File: gdb.info,  Node: Completion,  Next: Help,  Prev: Command Syntax,  Up: Commands
  837.  
  838. Command completion
  839. ==================
  840.  
  841.    GDB can fill in the rest of a word in a command for you, if there is
  842. only one possibility; it can also show you what the valid possibilities
  843. are for the next word in a command, at any time.  This works for GDB
  844. commands, GDB subcommands, and the names of symbols in your program.
  845.  
  846.    Press the TAB key whenever you want GDB to fill out the rest of a
  847. word.  If there is only one possibility, GDB fills in the word, and
  848. waits for you to finish the command (or press RET to enter it).  For
  849. example, if you type
  850.  
  851.      (gdb) info bre TAB
  852.  
  853. GDB fills in the rest of the word `breakpoints', since that is the only
  854. `info' subcommand beginning with `bre':
  855.  
  856.      (gdb) info breakpoints
  857.  
  858. You can either press RET at this point, to run the `info breakpoints'
  859. command, or backspace and enter something else, if `breakpoints' does
  860. not look like the command you expected.  (If you were sure you wanted
  861. `info breakpoints' in the first place, you might as well just type RET
  862. immediately after `info bre', to exploit command abbreviations rather
  863. than command completion).
  864.  
  865.    If there is more than one possibility for the next word when you
  866. press TAB, GDB sounds a bell.  You can either supply more characters
  867. and try again, or just press TAB a second time; GDB displays all the
  868. possible completions for that word.  For example, you might want to set
  869. a breakpoint on a subroutine whose name begins with `make_', but when
  870. you type `b make_TAB' GDB just sounds the bell.  Typing TAB again
  871. displays all the function names in your program that begin with those
  872. characters, for example:
  873.  
  874.      (gdb) b make_ TAB
  875. GDB sounds bell; press TAB again, to see:
  876.      make_a_section_from_file     make_environ
  877.      make_abs_section             make_function_type
  878.      make_blockvector             make_pointer_type
  879.      make_cleanup                 make_reference_type
  880.      make_command                 make_symbol_completion_list
  881.      (gdb) b make_
  882.  
  883. After displaying the available possibilities, GDB copies your partial
  884. input (`b make_' in the example) so you can finish the command.
  885.  
  886.    If you just want to see the list of alternatives in the first place,
  887. you can press `M-?' rather than pressing TAB twice. `M-?' means `META
  888. ?'.  You can type this either by holding down a key designated as the
  889. META shift on your keyboard (if there is one) while typing `?', or as
  890. ESC followed by `?'.
  891.  
  892.    Sometimes the string you need, while logically a "word", may contain
  893. parentheses or other characters that GDB normally excludes from its
  894. notion of a word.  To permit word completion to work in this situation,
  895. you may enclose words in `'' (single quote marks) in GDB commands.
  896.  
  897.    The most likely situation where you might need this is in typing the
  898. name of a C++ function.  This is because C++ allows function overloading
  899. (multiple definitions of the same function, distinguished by argument
  900. type).  For example, when you want to set a breakpoint you may need to
  901. distinguish whether you mean the version of `name' that takes an `int'
  902. parameter, `name(int)', or the version that takes a `float' parameter,
  903. `name(float)'.  To use the word-completion facilities in this
  904. situation, type a single quote `'' at the beginning of the function
  905. name.  This alerts GDB that it may need to consider more information
  906. than usual when you press TAB or `M-?' to request word completion:
  907.  
  908.      (gdb) b 'bubble( M-?
  909.      bubble(double,double)    bubble(int,int)
  910.      (gdb) b 'bubble(
  911.  
  912.    In some cases, GDB can tell that completing a name requires using
  913. quotes.  When this happens, GDB inserts the quote for you (while
  914. completing as much as it can) if you do not type the quote in the first
  915. place:
  916.  
  917.      (gdb) b bub TAB
  918. GDB alters your input line to the following, and rings a bell:
  919.      (gdb) b 'bubble(
  920.  
  921. In general, GDB can tell that a quote is needed (and inserts it) if you
  922. have not yet started typing the argument list when you ask for
  923. completion on an overloaded symbol.
  924.  
  925. 
  926. File: gdb.info,  Node: Help,  Prev: Completion,  Up: Commands
  927.  
  928. Getting help
  929. ============
  930.  
  931.    You can always ask GDB itself for information on its commands, using
  932. the command `help'.
  933.  
  934. `help'
  935. `h'
  936.      You can use `help' (abbreviated `h') with no arguments to display
  937.      a short list of named classes of commands:
  938.  
  939.           (gdb) help
  940.           List of classes of commands:
  941.           
  942.           running -- Running the program
  943.           stack -- Examining the stack
  944.           data -- Examining data
  945.           breakpoints -- Making program stop at certain points
  946.           files -- Specifying and examining files
  947.           status -- Status inquiries
  948.           support -- Support facilities
  949.           user-defined -- User-defined commands
  950.           aliases -- Aliases of other commands
  951.           obscure -- Obscure features
  952.           
  953.           Type "help" followed by a class name for a list of
  954.           commands in that class.
  955.           Type "help" followed by command name for full
  956.           documentation.
  957.           Command name abbreviations are allowed if unambiguous.
  958.           (gdb)
  959.  
  960. `help CLASS'
  961.      Using one of the general help classes as an argument, you can get a
  962.      list of the individual commands in that class.  For example, here
  963.      is the help display for the class `status':
  964.  
  965.           (gdb) help status
  966.           Status inquiries.
  967.           
  968.           List of commands:
  969.           
  970.           show -- Generic command for showing things set
  971.            with "set"
  972.           info -- Generic command for printing status
  973.           
  974.           Type "help" followed by command name for full
  975.           documentation.
  976.           Command name abbreviations are allowed if unambiguous.
  977.           (gdb)
  978.  
  979. `help COMMAND'
  980.      With a command name as `help' argument, GDB displays a short
  981.      paragraph on how to use that command.
  982.  
  983.    In addition to `help', you can use the GDB commands `info' and
  984. `show' to inquire about the state of your program, or the state of GDB
  985. itself.  Each command supports many topics of inquiry; this manual
  986. introduces each of them in the appropriate context.  The listings under
  987. `info' and under `show' in the Index point to all the sub-commands.
  988. *Note Index::.
  989.  
  990. `info'
  991.      This command (abbreviated `i') is for describing the state of your
  992.      program.  For example, you can list the arguments given to your
  993.      program with `info args', list the registers currently in use with
  994.      `info registers', or list the breakpoints you have set with `info
  995.      breakpoints'.  You can get a complete list of the `info'
  996.      sub-commands with `help info'.
  997.  
  998. `show'
  999.      In contrast, `show' is for describing the state of GDB itself.
  1000.      You can change most of the things you can `show', by using the
  1001.      related command `set'; for example, you can control what number
  1002.      system is used for displays with `set radix', or simply inquire
  1003.      which is currently in use with `show radix'.
  1004.  
  1005.      To display all the settable parameters and their current values,
  1006.      you can use `show' with no arguments; you may also use `info set'.
  1007.      Both commands produce the same display.
  1008.  
  1009.    Here are three miscellaneous `show' subcommands, all of which are
  1010. exceptional in lacking corresponding `set' commands:
  1011.  
  1012. `show version'
  1013.      Show what version of GDB is running.  You should include this
  1014.      information in GDB bug-reports.  If multiple versions of GDB are in
  1015.      use at your site, you may occasionally want to determine which
  1016.      version of GDB you are running; as GDB evolves, new commands are
  1017.      introduced, and old ones may wither away.  The version number is
  1018.      also announced when you start GDB.
  1019.  
  1020. `show copying'
  1021.      Display information about permission for copying GDB.
  1022.  
  1023. `show warranty'
  1024.      Display the GNU "NO WARRANTY" statement.
  1025.  
  1026. 
  1027. File: gdb.info,  Node: Running,  Next: Stopping,  Prev: Commands,  Up: Top
  1028.  
  1029. Running Programs Under GDB
  1030. **************************
  1031.  
  1032.    When you run a program under GDB, you must first generate debugging
  1033. information when you compile it.  You may start it with its arguments,
  1034. if any, in an environment of your choice.  You may redirect your
  1035. program's input and output, debug an already running process, or kill a
  1036. child process.
  1037.  
  1038. * Menu:
  1039.  
  1040. * Compilation::                 Compiling for debugging
  1041. * Starting::                    Starting your program
  1042.  
  1043. * Arguments::                   Your program's arguments
  1044. * Environment::                 Your program's environment
  1045. * Working Directory::           Your program's working directory
  1046. * Input/Output::                Your program's input and output
  1047. * Attach::                      Debugging an already-running process
  1048. * Kill Process::                Killing the child process
  1049. * Process Information::         Additional process information
  1050. * Threads::            Debugging programs with multiple threads
  1051.  
  1052. 
  1053. File: gdb.info,  Node: Compilation,  Next: Starting,  Up: Running
  1054.  
  1055. Compiling for debugging
  1056. =======================
  1057.  
  1058.    In order to debug a program effectively, you need to generate
  1059. debugging information when you compile it.  This debugging information
  1060. is stored in the object file; it describes the data type of each
  1061. variable or function and the correspondence between source line numbers
  1062. and addresses in the executable code.
  1063.  
  1064.    To request debugging information, specify the `-g' option when you
  1065. run the compiler.
  1066.  
  1067.    Many C compilers are unable to handle the `-g' and `-O' options
  1068. together.  Using those compilers, you cannot generate optimized
  1069. executables containing debugging information.
  1070.  
  1071.    GCC, the GNU C compiler, supports `-g' with or without `-O', making
  1072. it possible to debug optimized code.  We recommend that you *always*
  1073. use `-g' whenever you compile a program.  You may think your program is
  1074. correct, but there is no sense in pushing your luck.
  1075.  
  1076.    When you debug a program compiled with `-g -O', remember that the
  1077. optimizer is rearranging your code; the debugger shows you what is
  1078. really there.  Do not be too surprised when the execution path does not
  1079. exactly match your source file!  An extreme example: if you define a
  1080. variable, but never use it, GDB never sees that variable--because the
  1081. compiler optimizes it out of existence.
  1082.  
  1083.    Some things do not work as well with `-g -O' as with just `-g',
  1084. particularly on machines with instruction scheduling.  If in doubt,
  1085. recompile with `-g' alone, and if this fixes the problem, please report
  1086. it as a bug (including a test case!).
  1087.  
  1088.    Older versions of the GNU C compiler permitted a variant option
  1089. `-gg' for debugging information.  GDB no longer supports this format;
  1090. if your GNU C compiler has this option, do not use it.
  1091.  
  1092. 
  1093. File: gdb.info,  Node: Starting,  Next: Arguments,  Prev: Compilation,  Up: Running
  1094.  
  1095. Starting your program
  1096. =====================
  1097.  
  1098. `run'
  1099. `r'
  1100.      Use the `run' command to start your program under GDB.  You must
  1101.      first specify the program name (except on VxWorks) with an
  1102.      argument to GDB (*note Getting In and Out of GDB: Invocation.), or
  1103.      by using the `file' or `exec-file' command (*note Commands to
  1104.      specify files: Files.).
  1105.  
  1106.    If you are running your program in an execution environment that
  1107. supports processes, `run' creates an inferior process and makes that
  1108. process run your program.  (In environments without processes, `run'
  1109. jumps to the start of your program.)
  1110.  
  1111.    The execution of a program is affected by certain information it
  1112. receives from its superior.  GDB provides ways to specify this
  1113. information, which you must do *before* starting your program.  (You
  1114. can change it after starting your program, but such changes only affect
  1115. your program the next time you start it.)  This information may be
  1116. divided into four categories:
  1117.  
  1118. The *arguments.*
  1119.      Specify the arguments to give your program as the arguments of the
  1120.      `run' command.  If a shell is available on your target, the shell
  1121.      is used to pass the arguments, so that you may use normal
  1122.      conventions (such as wildcard expansion or variable substitution)
  1123.      in describing the arguments.  In Unix systems, you can control
  1124.      which shell is used with the `SHELL' environment variable. *Note
  1125.      Your program's arguments: Arguments.
  1126.  
  1127. The *environment.*
  1128.      Your program normally inherits its environment from GDB, but you
  1129.      can use the GDB commands `set environment' and `unset environment'
  1130.      to change parts of the environment that affect your program.
  1131.      *Note Your program's environment: Environment.
  1132.  
  1133. The *working directory.*
  1134.      Your program inherits its working directory from GDB.  You can set
  1135.      the GDB working directory with the `cd' command in GDB.  *Note
  1136.      Your program's working directory: Working Directory.
  1137.  
  1138. The *standard input and output.*
  1139.      Your program normally uses the same device for standard input and
  1140.      standard output as GDB is using.  You can redirect input and output
  1141.      in the `run' command line, or you can use the `tty' command to set
  1142.      a different device for your program.  *Note Your program's input
  1143.      and output: Input/Output.
  1144.  
  1145.      *Warning:* While input and output redirection work, you cannot use
  1146.      pipes to pass the output of the program you are debugging to
  1147.      another program; if you attempt this, GDB is likely to wind up
  1148.      debugging the wrong program.
  1149.  
  1150.    When you issue the `run' command, your program begins to execute
  1151. immediately.  *Note Stopping and continuing: Stopping, for discussion
  1152. of how to arrange for your program to stop.  Once your program has
  1153. stopped, you may call functions in your program, using the `print' or
  1154. `call' commands.  *Note Examining Data: Data.
  1155.  
  1156.    If the modification time of your symbol file has changed since the
  1157. last time GDB read its symbols, GDB discards its symbol table, and
  1158. reads it again.  When it does this, GDB tries to retain your current
  1159. breakpoints.
  1160.  
  1161. 
  1162. File: gdb.info,  Node: Arguments,  Next: Environment,  Prev: Starting,  Up: Running
  1163.  
  1164. Your program's arguments
  1165. ========================
  1166.  
  1167.    The arguments to your program can be specified by the arguments of
  1168. the `run' command.  They are passed to a shell, which expands wildcard
  1169. characters and performs redirection of I/O, and thence to your program.
  1170. Your `SHELL' environment variable (if it exists) specifies what shell
  1171. GDB if you do not define `SHELL', GDB uses `/bin/sh'.
  1172.  
  1173.    `run' with no arguments uses the same arguments used by the previous
  1174. `run', or those set by the `set args' command.
  1175.  
  1176. `set args'
  1177.      Specify the arguments to be used the next time your program is
  1178.      run.  If `set args' has no arguments, `run' executes your program
  1179.      with no arguments.  Once you have run your program with arguments,
  1180.      using `set args' before the next `run' is the only way to run it
  1181.      again without arguments.
  1182.  
  1183. `show args'
  1184.      Show the arguments to give your program when it is started.
  1185.  
  1186. 
  1187. File: gdb.info,  Node: Environment,  Next: Working Directory,  Prev: Arguments,  Up: Running
  1188.  
  1189. Your program's environment
  1190. ==========================
  1191.  
  1192.    The "environment" consists of a set of environment variables and
  1193. their values.  Environment variables conventionally record such things
  1194. as your user name, your home directory, your terminal type, and your
  1195. search path for programs to run.  Usually you set up environment
  1196. variables with the shell and they are inherited by all the other
  1197. programs you run.  When debugging, it can be useful to try running your
  1198. program with a modified environment without having to start GDB over
  1199. again.
  1200.  
  1201. `path DIRECTORY'
  1202.      Add DIRECTORY to the front of the `PATH' environment variable (the
  1203.      search path for executables), for both GDB and your program.  You
  1204.      may specify several directory names, separated by `:' or
  1205.      whitespace.  If DIRECTORY is already in the path, it is moved to
  1206.      the front, so it is searched sooner.
  1207.  
  1208.      You can use the string `$cwd' to refer to whatever is the current
  1209.      working directory at the time GDB searches the path.  If you use
  1210.      `.' instead, it refers to the directory where you executed the
  1211.      `path' command.  GDB replaces `.' in the DIRECTORY argument (with
  1212.      the current path) before adding DIRECTORY to the search path.
  1213.  
  1214. `show paths'
  1215.      Display the list of search paths for executables (the `PATH'
  1216.      environment variable).
  1217.  
  1218. `show environment [VARNAME]'
  1219.      Print the value of environment variable VARNAME to be given to
  1220.      your program when it starts.  If you do not supply VARNAME, print
  1221.      the names and values of all environment variables to be given to
  1222.      your program.  You can abbreviate `environment' as `env'.
  1223.  
  1224. `set environment VARNAME [=] VALUE'
  1225.      Set environment variable VARNAME to VALUE.  The value changes for
  1226.      your program only, not for GDB itself.  VALUE may be any string;
  1227.      the values of environment variables are just strings, and any
  1228.      interpretation is supplied by your program itself.  The VALUE
  1229.      parameter is optional; if it is eliminated, the variable is set to
  1230.      a null value.
  1231.  
  1232.      For example, this command:
  1233.  
  1234.           set env USER = foo
  1235.  
  1236.      tells a Unix program, when subsequently run, that its user is named
  1237.      `foo'.  (The spaces around `=' are used for clarity here; they are
  1238.      not actually required.)
  1239.  
  1240. `unset environment VARNAME'
  1241.      Remove variable VARNAME from the environment to be passed to your
  1242.      program.  This is different from `set env VARNAME ='; `unset
  1243.      environment' removes the variable from the environment, rather
  1244.      than assigning it an empty value.
  1245.  
  1246.    *Warning:* GDB runs your program using the shell indicated by your
  1247. `SHELL' environment variable if it exists (or `/bin/sh' if not).  If
  1248. your `SHELL' variable names a shell that runs an initialization
  1249. file--such as `.cshrc' for C-shell, or `.bashrc' for BASH--any
  1250. variables you set in that file affect your program.  You may wish to
  1251. move setting of environment variables to files that are only run when
  1252. you sign on, such as `.login' or `.profile'.
  1253.  
  1254. 
  1255. File: gdb.info,  Node: Working Directory,  Next: Input/Output,  Prev: Environment,  Up: Running
  1256.  
  1257. Your program's working directory
  1258. ================================
  1259.  
  1260.    Each time you start your program with `run', it inherits its working
  1261. directory from the current working directory of GDB.  The GDB working
  1262. directory is initially whatever it inherited from its parent process
  1263. (typically the shell), but you can specify a new working directory in
  1264. GDB with the `cd' command.
  1265.  
  1266.    The GDB working directory also serves as a default for the commands
  1267. that specify files for GDB to operate on.  *Note Commands to specify
  1268. files: Files.
  1269.  
  1270. `cd DIRECTORY'
  1271.      Set the GDB working directory to DIRECTORY.
  1272.  
  1273. `pwd'
  1274.      Print the GDB working directory.
  1275.  
  1276.